package cc.opcol.iot.app;

import cc.opcol.iot.server.sdk.JSInterface;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.ConfigurableApplicationContext;
import cc.opcol.iot.server.server.IoTServer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

@EntityScan(basePackages ={"cc.opcol.iot"})
@EnableJpaRepositories(basePackages ={"cc.opcol.iot"})
@ComponentScan("cc.opcol.iot")
@ServletComponentScan("cc.opcol.iot.app.web")
@EnableScheduling
@SpringBootApplication
public class App {
    public static void main(String[] args) {
        System.setProperty("spring.mvc.favicon.enabled","false");
        System.setProperty("spring.favicon.enabled","false");
        System.setProperty("server.tomcat.uri-encoding","UTF-8");
        System.setProperty("spring.thymeleaf.cache","false");
        System.setProperty("spring.devtools.restart.enabled","false");
        System.setProperty("spring.thymeleaf.mode","HTML");

        SpringApplication application = new SpringApplication(App.class);
        ConfigurableApplicationContext context = application.run(args);
        JSInterface jsInterface = context.getBean(JSInterface.class);
        jsInterface.setApplicationContext(context);
        AppConfiguration appConfiguration=context.getBean(AppConfiguration.class);
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    new IoTServer().start(appConfiguration.getIotPort());
                } catch (Exception e) {

                }
            }
        }).start();
    }
}
